#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
    int data;
    struct node *lchild;
    struct node *rchild;
} *btree,bnode;
btree recover(int n,int mid[],int post[])
{
    btree bt;
    int i;
    if(n<=0)

        return NULL;

    bt=(btree)malloc(sizeof(bnode));
    bt->data=post[n-1];
    bt->lchild=NULL;
   bt->rchild=NULL;
    for(i=0;i<n;i++)
    {
        if(mid[i]==bt->data)
            break;
    }
    bt->lchild=recover(i,mid,post);
    bt->rchild=recover(n-i-1,mid+i+1,post+i);
   return bt;


}
void preprint(btree bt)
{
    if(bt!=NULL)
      {

    printf("%d ",bt->data);
    preprint(bt->lchild);
    preprint(bt->rchild);
      }

}
int main()
{
    int n,i;
    btree bt=NULL;
     bt=(btree)malloc(sizeof(bnode));
    scanf("%d",&n);//cin>>n;
    int mid[n],post[n];

    for(i=0;i<n;i++)
    {
        scanf("%d",&post[i]);// cin>>mid[i];
    }  for(i=0;i<n;i++)
    {
        scanf("%d",&mid[i]);// cin>>mid[i];
    }

   bt= recover(n,mid,post);
    preprint(bt);
    return 0;
}
